//
//  HRZSearchNaviBar.m
//  EMarket
//
//  Created by 石头 on 2018/5/31.
//  Copyright © 2018 好日子. All rights reserved.
//

#import "HRZSearchNaviBar.h"

// Controllers

// Models

// Views

// Vendors

// Categories

// Others

@interface HRZSearchNaviBar ()
@property (nonatomic, strong) UITextField *searchField;
@property (nonatomic, strong) UIButton *rightClickView;
@end

@implementation HRZSearchNaviBar


// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
    
    [self setUpUI];
}

- (void) setUpUI {
    self.backgroundColor = [UIColor whiteColor];
    
    _searchField = [[UITextField alloc] initWithFrame:CGRectZero];
    UIImageView *leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_search"]];
    _searchField.leftView = leftView;
    _searchField.leftViewMode = UITextFieldViewModeAlways;
    
    UIImageView *rightView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_close"]];
    _searchField.rightView = rightView;
    _searchField.rightViewMode = UITextFieldViewModeWhileEditing;
    
    [self addSubview:_searchField];
    
    _rightClickView = [UIButton buttonWithType:UIButtonTypeCustom];
    [_rightClickView setTitle:@"取消" forState:UIControlStateNormal];
    
    [self addSubview:_rightClickView];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [_searchField mas_makeConstraints:^(MASConstraintMaker *make) {
        [make.left.mas_equalTo(self) setOffset:HRZMargin];
        [make.top.mas_equalTo(self) setOffset:25];
        make.right.mas_equalTo(self->_rightClickView.mas_left);
        make.bottom.mas_equalTo(self);
    }];
    
    [_rightClickView mas_makeConstraints:^(MASConstraintMaker *make) {
        [make.right.mas_equalTo(self) setOffset:HRZMargin];
        [make.top.mas_equalTo(self) setOffset:25];
        make.bottom.mas_equalTo(self);
        make.width.mas_equalTo(@60);
    }];
}


@end
